<template>
  <div class="index">
    <div class="container">
      <div class="heard_div">
        <div class="heard_title">统计列表</div>
        <div class="create_button" @click="createButton()" >
            打印当前列表
        </div>
      </div>
      <div class="noTime_div" v-if="!statisticData">暂无统计信息..</div>
      <table border="1" cellspacing="0" cellpadding="0" v-if="statisticData">
      <thead >
        <tr class="active">
          <th class="table-3">ID</th>
          <th class="table-8">真实姓名</th>
          <th class="table-12">手机号</th>
          <th class="table-12">创建日期</th>
          <th class="table-12">返佣金额</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(item, index) in statisticData.user_list" :key="item.id" :class="index%2 == 0 ? 'color1' : 'color2' ">
          <td class="middle">{{item.id}}</td>
          <td class="middle">{{item.name}}</td>
          <td class="middle">{{item.mobile}}</td>
          <td class="middle">{{item.create_date}}</td>
          <td class="middle">{{item.rearl_time_money}}</td>
        </tr>
      </tbody>
    </table>
    <div class="paging_div">
      <mo-paging v-if="statisticData"
            :page-index="Number(statisticData.page)" 
            :total="Number(statisticData.page_num)" 
            :page-size="statisticData.page_size" 
            @change="pageChange">
            </mo-paging>
    </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import getStatisticsList from "../../services/statistics/getStatisticsList";
import getStatistics from "../../services/statistics/getStatistics";
import MoPaging from "../common/paging";
import SearchInput from "../common/searchInput";
export default {
  name: "HelloWorld",
  components: {
    SearchInput,
    MoPaging
  },
  data() {
    return {
      params: {
        action: "getUserList",
        type: 2,
        pageon: 1
      },
      exportParams: {
        action: "getUserList",
        type: 3,
        pageon: 1
      },
      page: 1,
      statisticData: {}
    };
  },
  created() {
    // let _params = this.params;
    this.getStatisticsList(this.params);
  },
  methods: {
    // 导出execl
    createButton() {
      let pageon = this.page;
       window.location.href=`http://statistics.xianghuandian.com/statistics.php?action=getUserList&type=3&pageon=${pageon}`;  
      // this.getStatistics(this.exportParams);
      // this.$router.push({name:"AddUser"})
      // console.log("跳转到创建页面");
    },

    // 查看信息
    editInfo(id) {
      this.$router.push({ name: "EditInfo", query: { id: id } });
    },

    // 点击跳页
    pageChange(page) {
      console.log("page", page);
      this.params.pageon = page;
      this.page = page;
      this.getStatisticsList(this.params);
      // this.page = page;
      // this.getList();
    },

    // 搜索查询
    handleValueChange: function(value, key) {
      const vm = this;
      clearInterval(vm.timer); // 输入文字的时候先清理定时器
      vm.timer = setTimeout(() => {
        console.log("value", value, key);
        // let _params = vm.params;
        // _params.value = value;
        // if(value) {
        //   _params.search = true;
        // } else {
        //   _params.search = false;
        // }
        vm.getUserList();
      }, 1000); // 1秒后执行函数
    },

    getStatistics(params) {
      const vm = this;
      getStatistics(false, params).then(
        res => {
          // vm.statisticData = res.data;
          console.log("res", res.data);
        },
        erro => {
          console.log("erro", erro);
        }
      );
    },

    // 获取统计列表
    getStatisticsList(params) {
      const vm = this;
      getStatisticsList(false, params).then(
        res => {
          vm.statisticData = res.data;
          console.log("res", res.data);
          console.log('@@#@#@#@#', vm.statisticData);
        },
        erro => {
          vm.statisticData = erro.data;
          console.log("erro", erro);
        }
      );
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.index {
  position: absolute;
  height: 100%;
  width: 100%;
  background: url("../../assets/img1.jpg") no-repeat;
  background-size: 100%;
  .container {
    width: 1200px;
    margin: 0 auto;
    height: 100%;
    background: #f7f7f7;
    overflow: hidden;
  }
  .heard_div {
    display: flex;
    margin: 20px 30px 20px 20px;
    justify-content: space-between;
    .create_button {
      cursor: pointer;
      height: 30px;
      width: 150px;
      text-align: center;
      line-height: 30px;
      color: #fff;
      background: #5ebfb8;
      border-radius: 15px;
      margin-top: 10px;
    }
  }
   .noTime_div{
    text-align: center;
    font-size: 28px;
    margin-top: 100px;
  }
  .paging_div {
    text-align: center;
    margin-top: 30px;
  }
  .searchPage_div {
    width: 30%;
  }
  .heard_title {
    margin-left: 10px;
    font-size: 32px;
  }
  table {
    // border-color:#fff;
    width: 95%;
    border: 1px solid #999;
    color: #333;
    margin-left: 30px;
    table-layout: fixed;
  }
  .table-8 {
    width: 8%;
  }
  .table-12 {
    width: 12%;
  }
  .table-15 {
    width: 15%;
  }
  .table-3 {
    width: 3%;
  }
  .color1 {
    background: #fff;
  }
  .color2 {
    background: #e1e1e1;
  }
  .btn-info {
    color: #0275d8;
    cursor: pointer;
  }
  .btn-left {
    float: left;
    margin-left: 20px;
  }
  th {
    padding: 10px;
  }
  td {
    height: 30px;
    line-height: 30px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
</style>
